package com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it.networkassets;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.glsc.ngateway.common.base.domain.mysql.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import java.io.Serializable;
import java.time.LocalDate;

/**
 * 网络资产维护
 */
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Entity
@Where(clause = "deleted = 0")
@SQLDelete(sql = "update t_gw_it_net_assets_network_asset set deleted = UNIX_TIMESTAMP(NOW()) where id=?")
@SQLDeleteAll(sql = "update t_gw_it_net_assets_network_asset set deleted = UNIX_TIMESTAMP(NOW()) where id=?")
@Table(name = "t_gw_it_net_assets_network_asset", indexes = {@Index(name = "UK_SERIAL_NUM", columnList = "serial_num, deleted", unique = true)})
public class NetworkAssetMaintenance extends BaseEntity implements Serializable {

    private static final long serialVersionUID = -7756727289715188178L;

    @Column(name = "serial_num", columnDefinition = "varchar(64) not null comment '序列号'")
    private String serialNum;

    @Column(name = "vendor", columnDefinition = "varchar(64) not null comment '制造商'")
    private String vendor;

    @Column(name = "model", columnDefinition = "varchar(64) comment '型号'")
    private String model;

    @Column(name = "os", columnDefinition = "varchar(64) comment '系统'")
    private String os;

    @Column(name = "version", columnDefinition = "varchar(64) comment '版本'")
    private String version;

    @Column(name = "status", columnDefinition = "varchar(64) not null comment '状态'")
    private String status;

    @Column(name = "site", columnDefinition = "varchar(64) comment '站点'")
    private String site;

    @Column(name = "rack", columnDefinition = "varchar(64) comment '机柜'")
    private String rack;

    @Column(name = "unit", columnDefinition = "varchar(64) comment '单元'")
    private String unit;

    @Column(name = "manufacture_date", columnDefinition = "date comment '出厂日期'")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    protected LocalDate manufactureDate;

    @Column(name = "expired_date", columnDefinition = "date comment '质保到期'")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    protected LocalDate expiredDate;

    @Column(name = "asset_num", columnDefinition = "varchar(64) comment '资产标签'")
    private String assetNUM;

    @Column(name = "contract_num", columnDefinition = "varchar(64) comment '合同编号'")
    private String contractNUM;

}
